package kr.co.dayve.site.management.dao;

import kr.co.dayve.site.domain.CommunityBoard;
import kr.co.dayve.site.domain.Report;
import kr.co.dayve.site.domain.Vote;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import java.util.List;


public class CommunityBoardDaoImpl extends SqlMapClientDaoSupport implements CommunityBoardDao {
    public List getBoardListBySearchword(CommunityBoard board) {

        /**
         * Null 에러 방지용 공백 전환
         */
        if(board.getTitle() == null){
            board.setTitle("");
        }

        if(board.getWriter_id() == null){
            board.setWriter_id("");
        }

        if(board.getWriter_nick_name() == null){
            board.setWriter_nick_name("");
        }

        if(board.getContent() == null){
            board.setContent("");
        }

        return getSqlMapClientTemplate().queryForList("BOARD.getBoardListBySearchword", board, board.getCurrentPage() * board.getPageSize(), board.getPageSize());
    }

    public List getBoardListByNo(CommunityBoard board){
        return getSqlMapClientTemplate().queryForList("BOARD.getBoardListByNo", board, board.getCurrentPage() * board.getPageSize(), board.getPageSize());
    }

    public String getTotalCountBySearchword(CommunityBoard board) {
        return (String)getSqlMapClientTemplate().queryForObject("BOARD.getTotalCountBySearchword", board);
    }

    public String getTotalCountByNo(CommunityBoard board) {
        return (String)getSqlMapClientTemplate().queryForObject("BOARD.getTotalCountByNo", board);
    }

    public String writeBoard(CommunityBoard board){
        return Integer.toString(getSqlMapClientTemplate().update("BOARD.writeBoard", board));
    }

    public String updateBoard(CommunityBoard board){
        return Integer.toString(getSqlMapClientTemplate().update("BOARD.updateBoard", board));
    }

    public String deleteBoard(CommunityBoard board){
        return Integer.toString(getSqlMapClientTemplate().update("BOARD.deleteBoard", board));
    }

    public CommunityBoard getBoardByNo(String community_board_no){
        return (CommunityBoard)getSqlMapClientTemplate().queryForObject("BOARD.getBoardByNo", community_board_no);
    }

    public String updateReplyCount(CommunityBoard board){
        return Integer.toString(getSqlMapClientTemplate().update("BOARD.updateReplyCount", board));
    }

    public String updateHitCount(CommunityBoard board){
        return Integer.toString(getSqlMapClientTemplate().update("BOARD.updateHitCount", board));
    }

    public String updateVoteCount(CommunityBoard board){
        return Integer.toString(getSqlMapClientTemplate().update("BOARD.updateVoteCount", board));
    }

    public String updateNegativeCount(CommunityBoard board){
        return Integer.toString(getSqlMapClientTemplate().update("BOARD.updateNegativeCount", board));
    }

    public String updateReportCount(CommunityBoard board){
        return Integer.toString(getSqlMapClientTemplate().update("BOARD.updateReportCount", board));
    }

    public String checkDuplicateVote(Vote vote) {
        return (String)getSqlMapClientTemplate().queryForObject("BOARD.checkDuplicateVote", vote);
    }

    public String insertVoterToList(Vote vote) {
        return Integer.toString(getSqlMapClientTemplate().update("BOARD.insertVoterToList", vote));
    }

    public String communityBoardReport(Report report) {
        return Integer.toString(getSqlMapClientTemplate().update("BOARD.communityBoardReport", report));
    }

    public String checkDuplicateReport(Report report) {
        return (String)getSqlMapClientTemplate().queryForObject("BOARD.checkDuplicateReport", report);
    }

    public String updateBoardNotImage(CommunityBoard board) {
        return Integer.toString(getSqlMapClientTemplate().update("BOARD.updateBoardNotImage", board));
    }
}
